﻿$(function () {
    $("#go").click(function () {
        //1.有效性检查
        var content = $("#number").val().trim();
        if (content.length < 2) {
            alert("输入的字符不能少于2位");
            return;
        }
        $("#tb_result").html("");
        //2.ajax提交
        $.ajax({
            url: "/ashx/searchRecordHandler.ashx",
            async: false,
            type: "post",
            dataType: "json",
            data: { content: content },
            success: function (data) {
                if (data.Success) {
                    iniTable($.parseJSON(data.Data));
                } else {
                    alert(data.Message);
                }
            }
        });
    });

    //搜索按钮绑定回车键
    $(document).keydown(function (event) {
        if (event.keyCode == 13) {
            $("#go").click();
        }
    });

});


function iniTable(jsonstr) {
    $.each(jsonstr, function (idx, v) {
        var $tr = $("<tr></tr>");
        $tr.append("<td><a href='/ashx/downRecordHandler.ashx?file=" + v.fullname + "' target=_blank>" + v.filename + "</a></td>");
        $tr.append("<td>" + v.createtime + "</td>");

        $("#tb_result").append($tr);

    });
}